/* sockets.h */

/************************************************************************************
*                    Copyright Aquantia Corporation
*                              Freeware
*
* Description:
*
*   This file contains socket library abstractions. 
*   The platform integrator must provide the implementation of these 
*   functions if another socket library is used.
*
************************************************************************************/

/*! \file
    This file contains socket library abstractions. 
    The platform integrator must provide the implementation of these 
    functions if another socket library is used.
*/

#ifndef AQ_SOCKETS_TOKEN
#define AQ_SOCKETS_TOKEN

#include "sockets_platform.h"

/*! \defgroup Sockets Socket Library
  @{*/

/*! Socket errors enumeration */
enum tcpServerErrors
{
  TCP_SERVER_E_OK             =  0,
  TCP_SERVER_E_SOCKET_INIT    = -1,
  TCP_SERVER_E_SOCKET_CREATE  = -2,
  TCP_SERVER_E_SOCKET_SET_OPT = -3,
  TCP_SERVER_E_SOCKET_GET_OPT = -4,
  TCP_SERVER_E_SOCKET_BIND    = -5,
  TCP_SERVER_E_SOCKET_LISTEN  = -6,
  TCP_SERVER_E_GET_HOST_NAME  = -7,
  TCP_SERVER_E_SOCKET_SEND    = -8,
  TCP_SERVER_E_SOCKET_RECV    = -9
};

/*! Function initiates use of socket library if necessary. 
    Non-zero value indicates failure. */
int sockInitialize();

/*! Function terminates use of socket library if necessary. 
    Non-zero value indicates failure. */
int sockClose();


/*! Returns error string for the last sockets operation that failed */
char* get_socket_error();

/*! Compares last socket error with specified POSIX socket error code */
int is_socket_error_equal(int code);

/*! Retrieves the standard host name for the local computer */
int get_host_name(char* name, int namelen);

/*! Function sets specified TCP keep-alive options. 
    Non-zero return value indicates failure during setting. 
    Warning can be printed to verbose string. */
int setTcpKeepAliveOptions(
  SOCKET socket,            /*!< Target socket to set options. */
  int time,                 /*!< The length of silence in seconds before a keep-alive ACK is sent. */
  int timeSpecified,        /*!< The length of silence is specified. */
  int interval,             /*!< The interval between keep-alive ACKs, after keep-alive checking is started. */
  int intervalSpecified,    /*!< The interval between keep-alive ACKs is specified. */
  int count,                /*!< The number of keep-alive attempts to make before declaring the socket broken. */
  int countSpecified,       /*!< The number of keep-alive attempts is specified. */
  char* verbose             /*!< Target system warnings received during options setting. */
);

/*! Function reads TCP keep-alive options.
   Non-zero return value indicates failure during reading. */
int getTcpKeepAliveOptions(
  SOCKET socket,          /*!< Target socket to get options. */
  int* time,              /*!< The length of silence in seconds before a keep-alive ACK is sent. */
  int* timeRead,          /*!< The length of silence was read. */
  int* interval,          /*!< The interval between keep-alive ACKs, after keep-alive checking is started. */
  int* intervalRead,      /*!< The interval between keep-alive ACKs was read. */
  int* count,             /*!< The number of keep-alive attempts to make before declaring the socket broken. */
  int* countRead          /*!< The number of keep-alive attempts was read. */
);

/*@}*/

#endif